package cn.easy.mortgage.config;

import com.google.common.collect.Lists;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caosk
 * @Description: 微信过滤器配置
 * @date 2015年5月28日 下午9:03:26
 */
@Configuration
public class WxMpFilterConfig {
    @Autowired
    private WxMpFilter wxMpFilter;
    @Autowired
    private WxMpService wxMpService;

    @Bean
    FilterRegistrationBean wechatMpFilter() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(wxMpFilter);
        bean.setUrlPatterns(Lists.newArrayList("/wechat/mp/*"));
        return bean;
    }

    @Bean
    FilterRegistrationBean wechatMpAuthFilter() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new WxMpAuthFilter(wxMpService));
        bean.addInitParameter("excludeUrls", "/app/mp/sendValidSms,/app/mp/login,/app/mp/errBrowser,/app/mp/scanLogin,app/mp/scanLoginValid");
        bean.setUrlPatterns(Lists.newArrayList("/app/mp/*"));
        return bean;
    }
}
